import React, {Component} from 'react'
import {connect} from 'react-redux'
import {withRouter} from 'react-router-dom'

import HotNews from "./components/HotNews/HotNews"
import {WhiteSpace} from "antd-mobile"
import TopicBanner from "./components/TopicBanner/TopicBanner";
import {GlobalStore} from "../../../../context";
import DownloadHint from "../../../../shared-components/DownloadHint/DownloadHint";

class Recommend extends Component {

    static contextType = GlobalStore
    constructor(props) {
        super(props)
        this.state = {
            downloadShow: true,
        }
    }

    componentDidMount() {
        const newsList = this.props.news.newsList
        this.setDownloadShow()
        if (newsList.length === 0) {
            this.props.doFetchNewsList({
                startId: 0,
                endId: 10,
            })
        }
        this.props.doFetchGameList()

        // this.props.doFetchStarRankListNoToken()
    }

    setDownloadShow = () => {
        const downloadShow = this.context.downloadApp.show
        this.setState({
            downloadShow,
        })
    }

    hidden = () => {
        this.context.downloadApp.hidden()
        this.setState({
            downloadShow: false,
        })
    }


    render() {

        const download = this.state.downloadShow

        return (
            <div>
                {/*<div style={{*/}
                {/*    background: '#fff',*/}
                {/*}}>*/}
                {/*    /!*{download ? <DownloadHint onHidden={this.hidden}/> : null}*!/*/}
                {/*    <WhiteSpace size='xl'/>*/}
                {/*    <TopicBanner/>*/}
                {/*    <WhiteSpace size='xl'/>*/}
                {/*    /!*<GameCarousel />*!/*/}
                {/*</div>*/}

                {/*<WhiteSpace size='xl'/>*/}

                {/*<AIResult />*/}

                {/*<WhiteSpace size='xl'/>*/}

                {/*<WhiteSpace size='xl'/>*/}
                {/*<GameCarousel />*/}
                {/*<WhiteSpace/>*/}

                {/*<WhiteSpace size='xl'/>*/}
                {/*<ImageCarousel />*/}

                {/*<WhiteSpace size='xl'/>*/}
                {/*<Topic />*/}
                {/*<TopicBanner/>*/}

                {/*<WhiteSpace size='xl'/>*/}
                {/*<WhiteSpace size='xl'/>*/}
                {/*<Top3Steamers/>*/}

                {/*<WhiteSpace/>*/}
                <HotNews />


                <WhiteSpace size='xl'/>
                {/*<HotGames />*/}
            </div>
        )
    }

}



const mapState = state => ({
    game: state.game,
    news: state.news,
    home: state.home,
})

const mapDispatch = dispatch => ({
    doFetchNewsList: (payload) => dispatch.news.doFetchNewsList(payload),
    doFetchSinaNewsList: (payload) => dispatch.home.doFetchSinaNewsList(payload),
    doGetAIResultList: (payload) => dispatch.game.doGetAIResultList(payload),
    doFetchGameList: (payload) => dispatch.home.doFetchGameList(payload),
    doFetchStarRankListNoToken: (payload) => dispatch.home.doFetchStarRankListNoToken(payload),
})


export default connect(mapState, mapDispatch)(withRouter(Recommend))
